/**
 * @(#) MedicalMoneyProxy.as
 *
 * @date		2011. 03. 25
 * @version		1.0
 * @author		baek kwang hyoun
 * @description	건강보험증 Proxy - Proxy
 * 				건강보험증를 조회를한다.
 */
package com.skt.common_hr.healthchkreq.model
{
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.healthchkreq.model.vo.healthchkreqFileUpLoadVO;
	import com.skt.common_hr.healthchkreq.model.vo.healthchkreqVO;
	import com.wcl.dataloader.*;
	import com.wcl.utils.DateUtil;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class HealthchkreqProxy extends CommonProxy
	{
		public static const NAME:String = "HealthchkreqProxy";

		public static const LOAD_MEDICALMONEY_LIST_COMPLETE:String	= "LoadMedicalMoneyListComplete";
		public static const LOAD_MEDICALMONEY_LIST_FAILED:String	= "LoadMedicalMoneyListFailed";


		public var mainList:ArrayCollection;
		public var codeList:ArrayCollection;
		
		public var O_MEDCK:String;
		public var O_ENAME:String;
		public var O_ZYEAR:String;
		//2015.03.20 정상아
		public var O_MEDCT:String;
		public var O_AMEDCT:String;
		
		
		
		
		
		public var subTabList:ArrayCollection; 
		public var acOitab:ArrayCollection;
		public var subTabFileList:healthchkreqFileUpLoadVO;
		
		
		public var key:String;

		//지원기준
		public var loadFaultMessage:String;

		/**
		 * 생성자
		 *
		 * @param
		 * @return void
		 */
		public function HealthchkreqProxy(data:Object=null)
		{
			super(NAME, data);
		}

		// 메인리스트 호출
		public function loadList(pernr:String,  I_ZYEAR:String, setFunc:Function):void
		{
			var params:Object = new Object();
			params["I_PERNR"] = pernr;
			params["I_ZYEAR"] = I_ZYEAR;
			
			loadData("Z_HR_HE01", params, loadListResult, listFault, setFunc); 
		}
		
		
		public function loadListResult(event:ResultEvent):void
		{
			if(retCode==0) {
				O_MEDCK	= event.result.O_MEDCK;
				O_ENAME	= event.result.O_ENAME;
				O_ZYEAR	= event.result.O_ZYEAR;
				O_MEDCT = event.result.O_MEDCT;
				O_AMEDCT = event.result.O_AMEDCT;
				mainList 		= parseMainList(event.result.OTAB);
				codeList		= event.result.T_MEDCK;
				event.result.func(this);
			}
			else {
				Alert.show(retText);
			}
		}

		
		// 삭제
 		public function deleteList(selecteItem:Object, setFunc:Function):void
		{
			var params:Object = new Object();
			params["I_ACTIO"] = "DEL";
			params["I_PERNR"] = Variables.myPernr;
			params["I_HENUM"] = selecteItem.HENUM;
			
			loadData("Z_HR_HE02", params, deleteListResult, listFault, setFunc); 
		}
		public function deleteListResult(event:ResultEvent):void
		{
			if(retCode==0) {
				event.result.func();
			}
			else {
				Alert.show(retText);
			}
		}			
		

		private function parseMainList(recArr:ArrayCollection):ArrayCollection
		{
			var retArr:ArrayCollection = new ArrayCollection();
			
			for each(var obj:Object in recArr){
				//var retObj:MedicalSubTabVO = new MedicalSubTabVO();			
				var retObj:healthchkreqVO = new healthchkreqVO();
				for(var field:String in obj) {					
				if(retObj.hasOwnProperty(field)==false ) {
                	continue;
                }
                         
					if(field == "MEDAT1" || field == "MEDAT2" ) {					
						retObj[field+'_DT'] = DateUtil.stringToDateTime(obj[field]);
						retObj[field+'_TX'] = DateUtil.toDefaultString(retObj[field+'_DT']);
//						retObj[field+'_JSON'] = DateUtil.toBasicString(retObj[field+'_DT']);
						retObj[field] = obj[field];
					}
					else if(field == "BETRG") {
						//retObj[field] = Math.round(obj[field]*100);
					}
					else {
						retObj[field] = obj[field];
					}					
				} 
				retArr.addItem(retObj);				
			}
			return retArr;
		}
		
				
		private function toJsonType(vo:Object):Object {
			var retObj:Object = new Object;
			for(var field:String in vo) {
				if(vo[field] is Date) {
					retObj[field] = DateUtil.toBasicString(vo[field]);	
				}
				else {
					retObj[field] = vo[field];	
				}
				trace(retObj[field]);
			} 
			return retObj;
		}
		
		private function listFault(event:FaultEvent):void
		{
			Alert.show(retText);
		}		
		
		
	}
}